package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.Vo;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询自媒体文章内容
     * @param wmNewsPageReqDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult newsList(@RequestBody WmNewsPageReqDto wmNewsPageReqDto){
        return wmNewsService.newsList(wmNewsPageReqDto);
    }

    /**
     * 发布文章或保存草稿或修改文章
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.submit(wmNewsDto);
    }

    /**
     * 根据文章id查询文章详情
     * @param newsId
     * @return
     */
    @GetMapping("/one/{newsId}")
    public ResponseResult one(@PathVariable("newsId") Integer newsId){
        return wmNewsService.one(newsId);
    }

    /**
     * 自媒体文章上架和下架功能
     * @param dto
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto){
        return wmNewsService.downOrUp(dto);
    }


    /**
     * 后台查询文章
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult findHumanReview(@RequestBody NewsAuthDto newsAuthDto){
        return wmNewsService.findHumanReview(newsAuthDto);
    }

    /**
     * 后台管理员根据id查询文章
     * @param id
     * @return
     */
    @GetMapping("one_vo/{id}")
    public ResponseResult findWmNewsById(@PathVariable("id") Integer id){
        return wmNewsService.findWmNewsById(id);
    }

    /**
     * 后台管理员审核文章
     * @return
     */
    @PostMapping("/auth_pass")
    public ResponseResult HumanReviewNewsPass(@RequestBody NewsAuthDto newsAuthDto){
        return wmNewsService.humanReviewNews(newsAuthDto);
    }

    @PostMapping("/auth_fail")
    public ResponseResult HumanReviewNewsFail(@RequestBody NewsAuthDto newsAuthDto){
        return wmNewsService.humanReviewNews(newsAuthDto);
    }
}
